package com.jic.market.mapper;

import com.jic.market.orm.BaseMapper;
import com.jic.market.entity.PromotionSingleRuleEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface PromotionSingleRuleEntityMapper extends BaseMapper<PromotionSingleRuleEntity>{

    int updatePrice(PromotionSingleRuleEntity singleRuleEntity);

    int updateLimit(PromotionSingleRuleEntity singleRuleEntity);

    @Override
    int insert(PromotionSingleRuleEntity limitSingleRuleEntity);

    /**
     * 根据 促销活动id 和 商品id 删除
     * @param promotionId
     * @param productId
     * @return
     */
    Integer deleteEntityByPromotionIdAndMpId
    (@Param("promotionId") Long promotionId, @Param("productId") Long productId);

    /**
     * 根据 促销id 和 商品id 查询
     * @param promotionId
     * @param productId
     * @return
     */
    PromotionSingleRuleEntity getEntityByPromotionIdAndMpId
    (@Param("promotionId") Long promotionId, @Param("productId") Long productId);

    /**
     * 根据 促销id  查询
     * @param promotionId
     * @return
     */
    List<PromotionSingleRuleEntity> queryPromotionSingleRuleById
    (@Param("promotionId") Long promotionId);



    /**
     * 根据 促销id 和 商品id 和spu/sku查询
     * @param promotionSingleRule
     * @return
     */
    PromotionSingleRuleEntity queryEntityByPromotionIdAndMpId(PromotionSingleRuleEntity promotionSingleRule);

    int updatePromotionSingleRule(PromotionSingleRuleEntity promotionSingleRule);

    int deleteByLimitTypeAndPidAndRef(@Param("promotionId")Long promotionId, @Param("mpId")Long mpId, @Param("typeOfProduct")Integer limitType);


    @Select("select content_value from promotion_single_rule where promotion_id = #{promotionId} and mp_id=#{skuId} and type_of_product = 2 and delete_flag = 0 limit 1")
    BigDecimal queryContentValueByPromotionIdAndMpId(@Param("promotionId") Long promotionId, @Param("skuId") Long skuId);

    int insertBatch(@Param("items") List<PromotionSingleRuleEntity> items);
}